package com.ruoyi.goodscar.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goodscar.domain.GoodsCar;
import com.ruoyi.goodscar.service.IGoodsCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车信息Controller
 *
 * @author ruoyi
 * @date 2025-05-05
 */
@RestController
@RequestMapping("/goodscar/goodscar")
public class GoodsCarController extends BaseController
{
    @Autowired
    private IGoodsCarService goodsCarService;

    /**
     * 查询汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsCar goodsCar)
    {
        startPage();
        List<GoodsCar> list = goodsCarService.selectGoodsCarList(goodsCar);
        return getDataTable(list);
    }

    /**
     * 导出汽车信息列表
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:export')")
    @Log(title = "汽车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsCar goodsCar)
    {
        List<GoodsCar> list = goodsCarService.selectGoodsCarList(goodsCar);
        ExcelUtil<GoodsCar> util = new ExcelUtil<GoodsCar>(GoodsCar.class);
        util.exportExcel(response, list, "汽车信息数据");
    }

    /**
     * 获取汽车信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return success(goodsCarService.selectGoodsCarByCarId(carId));
    }

    /**
     * 新增汽车信息
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:add')")
    @Log(title = "汽车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCar goodsCar)
    {
        return toAjax(goodsCarService.insertGoodsCar(goodsCar));
    }

    /**
     * 修改汽车信息
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:edit')")
    @Log(title = "汽车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCar goodsCar)
    {
        return toAjax(goodsCarService.updateGoodsCar(goodsCar));
    }

    /**
     * 删除汽车信息
     */
    @PreAuthorize("@ss.hasPermi('goodscar:goodscar:remove')")
    @Log(title = "汽车信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(goodsCarService.deleteGoodsCarByCarIds(carIds));
    }
}
